﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using ThanNhanTao.Server.Entities;

namespace ThanNhanTao.Report
{
    public partial class rptPhieuThanhToanNgoaiTruTheoThangDetailPhanLoaiBHYT : DevExpress.XtraReports.UI.XtraReport
    {
        List<PhieuThanhToanNoiTruEntities> listThanhToanTheoLoai;
        int soDongInPhieu = 0;
        public rptPhieuThanhToanNgoaiTruTheoThangDetailPhanLoaiBHYT(List<PhieuThanhToanNoiTruEntities> listThanhToanTheoLoai, int soDongInPhieu)
        {
            InitializeComponent();
            this.listThanhToanTheoLoai = listThanhToanTheoLoai;
            this.soDongInPhieu = soDongInPhieu;
        }

        public void BindPhanLoai(string stt)
        {
            colSTT.Text = stt;
            colPhanLoaiTrongYeuCau.DataBindings.Add("Text", DataSource, "MoTa");
        }

        public void BindData()
        {
            //colMaYeuCau.DataBindings.Add("Text", DetailReport.DataSource, "MaYeuCau");
            colTenYeuCau.DataBindings.Add("Text", DetailReport.DataSource, "TenYeuCauChayThan");
            colTenDonViTinh.DataBindings.Add("Text", DetailReport.DataSource, "TenDonViTinh");
            colSoLuong.DataBindings.Add("Text", DetailReport.DataSource, "SoLuong");
            colGiaYeuCau.DataBindings.Add("Text", DetailReport.DataSource, "GiaYeuCau", "{0:#,##0}");
            colThanhTien.DataBindings.Add("Text", DetailReport.DataSource, "ThanhTien", "{0:#,##0}");
        }

        private void Detail_AfterPrint(object sender, EventArgs e)
        {
            if (listThanhToanTheoLoai != null)
            {
                byte phanLoaiBHYT = (byte)GetCurrentColumnValue("PhanLoaiBHYT");
                List<PhieuThanhToanNoiTruEntities> listThanhToanTheoLoaiFinal = listThanhToanTheoLoai.FindAll(u => u.PhanLoaiBHYT == phanLoaiBHYT);
                for (int i = 0; i < soDongInPhieu; i++)
                {
                    listThanhToanTheoLoaiFinal.Add(new PhieuThanhToanNoiTruEntities
                    {
                        MaLoaiYeuCau = "",
                        TenLoaiYeuCau = "",
                        TenYeuCauChayThan = "",
                        PhanLoaiBHYT = phanLoaiBHYT
                    });
                }
                DetailReport.DataSource = listThanhToanTheoLoaiFinal;
                BindData();
            }
        }
    }
}
